#!/bin/sh

if [ x$1 = x ]; then
	echo "Usage: $0 /path/to/root"
	exit
fi


for dir in dev etc/init.d sys proc root var tmp; do
	mkdir -p ${1}/${dir}
done

cp -a ${CROSSTOOL_PATH}/${TARGET_PLAT}/lib/*.so* ${1}/usr/lib/

if [ ! -c ${1}/dev/console ]; then
	mknod -m 666 ${1}/dev/console c 5 1
fi

cp -v ${PREGEN_PATH}/inittab ${1}/etc

cp -v ${PREGEN_PATH}/rcS ${1}/etc/init.d/rcS
chmod 777 ${1}/etc/init.d/rcS

if [ x${MWL_USE_MDEV} != x"1" ]; then
	echo -n "Installing udev ... "
	mkdir -p ${1}/etc/udev/rules.d
	cp ${PREGEN_PATH}/20-names.rules ${1}/etc/udev/rules.d/

	sed -i '/^mdev/d' ${1}/etc/init.d/rcS
else
	echo -n "Installing mdev ... "
	sed -i '/^udev/d' ${1}/etc/init.d/rcS
	sed -i 's/udev/mdev/g' ${1}/etc/init.d/rcS
	cp ${PREGEN_PATH}/mdev.conf ${1}/etc/
	cp -a ${PREGEN_PATH}/mdev ${1}/lib/
fi
echo "OK."


